#include<bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
int t;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&t);
    while(t!=0){
            t--;
        int n;
        scanf("%d",&n);
        int a[n+1];
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        if(a[1]==a[n])cout<<1<<endl;
        if(a[1]==a[2]-1 && a[2]==a[3]-1)cout<<0<<endl;
        else cout<<a[1]+a[5];
    }


}

